package intelligentcity.gui;

import intelligentcity.conf.Conf;
import intelligentcity.model.City;
import intelligentcity.model.traffic.Traffic;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.Timer;

public abstract class Gui extends JPanel implements ActionListener {

    private static final long serialVersionUID = 4241761844901973180L;

    protected City city;
    protected Traffic traffic;
    protected Timer timer;

    protected Gui() {
        timer = new Timer(Conf.timing, this);
    }

    public void paint(Graphics g) {
        super.paint(g);

        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.translate(25, 5);

        CityDrawer.drawCity(g2d, city);
        TrafficDrawer.drawTraffic(g2d, traffic);
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        repaint();
    }

}
